package com.binson.apppay.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.binson.apppay.exception.fallback.MyExceptionUtil;
import com.binson.apppay.exception.handler.FlowExceptionHandler;
import com.binson.common.core.domain.R;
import com.binson.common.model.AppModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@RequestMapping("app")
@RefreshScope
public class AppPayController {
    @Value("${server.port}")
    int port;
    @Value("${test2}")
    String apptest;
    @RequestMapping(value = "pay",method= RequestMethod.GET)
    @SentinelResource(value = "pay",blockHandlerClass = FlowExceptionHandler.class,blockHandler = "test",
            fallback = "payfallback",fallbackClass = {MyExceptionUtil.class}
    )
    @ResponseBody
    R<?> test(@RequestBody AppModel appModel) throws Exception
    {
        appModel.setAge(port);
        R<AppModel> r=R.ok(appModel);
        log.info("请求端口："+port+"，接受到pay{}",appModel);
        return r;
    }
    @RequestMapping(value = "test2",method= RequestMethod.GET)
    @ResponseBody
    R<?> test2(){
        log.info("获取的到值"+apptest);
        return R.ok(apptest);
    }
}
